$('#btn-login').on('click', function() {
    $('#modal-login').modal({
      relatedTarget: this,
      onConfirm: function(e) {
        login(e.data[0], e.data[1])
      },
      onCancel: function(e) {
      }
    });
});

$("#btn-logout").on('click', function() {
    $("#modal-logout").modal({
        relatedTarget: this,
        onConfirm: function(e) {
            postLogout(d => {
              clearToken()
              window.location.reload()
            }, d => {
              alert("注销失败\n" + d.msg)
            })
        }
    })
})

$("#createBtn").on('click', function() {
  $("#modal-create").modal({
    relatedTarget: this,
    onConfirm: function(e) {
      postCreate(e.data, d => {
        alert("创建成功")
        window.location.reload()
      }, d => {
        alert("创建失败\n" + d.msg)
      })
    }
  })
})

$("#joinBtn").on('click', function() {
  $("#modal-join").modal({
    relatedTarget: this,
    onConfirm: function(e) {
      postJoin(e.data[0], e.data[1], d => {
        alert("加入成功")
        window.location.reload()
      }, d => {
        alert("加入失败\n" + d.msg)
      })
    }
  })
})

$("#mTeam").on('click', function() {
    $("#modal-modify").modal({
       relatedTarget: this,
       onConfirm: function(e) {
         postTeamModify(e.data[0], e.data[1], d => {
           alert("修改成功")
           window.location.reload()
         }, d => {
           alert("加入失败\n" + d.msg)
         })
       }
    })
})

$("#qTeam").on("click", function() {
  $("#modal-quit").modal({
    relatedTarget: this,
    onConfirm: function(e) {
      postQuitTeam(d => {
        alert("退出成功")
        window.location.reload()
      }, d => {
        alert("退出失败\n" + d.msg)
      })
    }
  })
})

$("#lTeam").on("click", function() {
  $("#modal-list").modal({
    relatedTarget: this
  })
})